package com.cyy.demo.test.thread;

import java.util.concurrent.*;

public class ServiceThreadPool {

    public static void main(String[] args) {
        long start = System.currentTimeMillis();
        ExecutorService executorService = Executors.newFixedThreadPool(2);

        FutureTask<String> orderfutureTask = new FutureTask<>(new OrderThread());
        FutureTask<String> pointsfutureTask = new FutureTask<>(new PointsThread());
        executorService.submit(orderfutureTask);
        executorService.submit(pointsfutureTask);

        try {
            String order = orderfutureTask.get();
            String points = pointsfutureTask.get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        System.out.println("共耗时："+ (System.currentTimeMillis() - start));
    }



}

class OrderThread1 implements Callable {
    @Override
    public String call() {
        System.out.println("开始获取订单");
        long start = System.currentTimeMillis();
        try {
            Thread.sleep(1500);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("订单耗时："+ (System.currentTimeMillis() - start));
        return "1000";
    }
}

class PointsThread1 implements Callable{
    @Override
    public String call() {
        System.out.println("开始获取积分");
        long start = System.currentTimeMillis();
        try {
            Thread.sleep(1200);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println("积分耗时："+ (System.currentTimeMillis() - start));
        return "1000";
    }
}
